
//单个上传
function uploadInit() {
    upload.render({
        elem: '#uploadFile'
        , url: '/tFile/fileUpload' //改成您自己的上传接口
        , field: 'myfiles'
        ,accept:"file"
        , data: {uid: myuid,
            fid:fid
        }
        , done: function (res) {
            layer.msg('上传成功');
            console.log(res)
        }
    });
    $("#uploadFile").click();
}


//查看图片
function openimg(type,fname,dir) {
    var src="E:\\upload\\图片\\a1000\\818ab4441e4d451980db02e63e1f2179_1618800734(1).png";
    src="/upload/"+type+"/"+dir+"/"+fname;
    var json={
        "title": "", //相册标题
        "id": 123, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [   //相册包含的图片，数组格式
            {
                "alt": "图片名",
                "pid": 666, //图片id
                "src": src, //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    };
    layer.photos({
        photos: json
        ,shift: 1 //0-6的选择，指定弹出图片动画类型，默认随机
    });

    // layer.open({
    //     type: 1,
    //     title: false,
    //     closeBtn: 0,
    //     area: ['auto'],
    //     skin: 'layui-layer-nobg', //没有背景色
    //     shadeClose: true,
    //     content: "<img  style=width:1000px;height:800px src=\""+src+"\">"
    // });
}



//图片放大1.0
// .over {position: fixed; left:0; top:0; width:100%; z-index:100;}
// .tempContainer {position:fixed; width:100%;height:90%;
//     margin-right:0px; margin-left:0px; text-align:center; z-index:101;
//     margin-bottom: 50px;
function fangdaimg() {
    //  $(document).ready(function () {
    var imgsObj = $('.amplifyImg li img');//需要放大的图像. li
    if (imgsObj) {
        $.each(imgsObj, function () {
            $(this).click(function () {

                var currImg = $(this);

                var currImgid=currImg.attr("id");
                console.log(currImgid);
                coverLayer(1);
                var tempContainer = $('<div class=tempContainer></div>');//图片容器
                with (tempContainer) {//width方法等同于$(this)
                    appendTo("body");
                    var windowWidth = $(window).width();
                    var windowHeight = $(window).height();
                    //获取图片原始宽度、高度
                    var orignImg = new Image();
                    orignImg.src = currImg.attr("src");
                    var currImgWidth = orignImg.width;
                    var currImgHeight = orignImg.height;
                    if (currImgWidth < windowWidth) {//为了让图片不失真，当图片宽度较小的时候，保留原图
                        if (currImgHeight < windowHeight) {
                            var topHeight = (windowHeight - currImgHeight) / 2;
                            if (topHeight > 35) {/*此处为了使图片高度上居中显示在整个手机屏幕中：因为在android,ios的微信中会有一个title导航，35为title导航的高度*/
                                topHeight = topHeight - 35;
                                //css('top',topHeight);
                                css('top', 0);
                            } else {
                                css('top', 0);
                            }
                            var myimghtml = "<img  border=0 currImgid="+currImgid+" id=myfangdaimg class=\"myimg\" src=\"" + orignImg.src + "\">";
                            //html("3213213 < img border=0 src=' + currImg.attr('src') + '>");
                            html(myimghtml);
                        } else {
                            css('top', 0);
                            html("< img border=0 src=' + currImg.attr('src') + ' height='+windowHeight+'>");
                        }
                    } else {
                        var currImgChangeHeight = (currImgHeight * windowWidth) / currImgWidth;
                        if (currImgChangeHeight < windowHeight) {
                            var topHeight = (windowHeight - currImgChangeHeight) / 2;
                            if (topHeight > 35) {
                                topHeight = topHeight - 35;
                                css('top', topHeight);
                            } else {
                                css('top', 0);
                            }
                            html("< img border=0 src=' + currImg.attr('src') + ' width='+windowWidth+';>");
                        } else {
                            css('top', 0);
                            html("< img border=0 src=' + currImg.attr('src') + ' width='+windowWidth+'; height='+windowHeight+'>");
                        }
                    }
                }
                tempContainer.click(function () {
                    $(this).remove();
                    coverLayer(0);
                });
            });
        });
    } else {
        // return false;
    }

    //使用禁用蒙层效果
    function coverLayer(tag) {
        with ($('.over')) {
            if (tag == 1) {
                css('height', $(document).height());
                css('display', 'block');
                css('opacity', 1);
                css("background-color", "#FFFFFF");
                css("background-color", "rgba(0,0,0,0.7)");  //蒙层透明度
            } else {
                css('display', 'none');
            }
        }
    }
}

//多文件列表示例
// <div className="layui-upload">
//     <button type="button" className="layui-btn layui-btn-normal" id="fileList">选择多文件</button>
//     <div className="layui-upload-list">
//         <table className="layui-table">
//             <thead>
//             <tr>
//                 <th>文件名</th>
//                 <th>大小</th>
//                 <th>状态</th>
//                 <th>操作</th>
//             </tr>
//             </thead>
//             <tbody id="uploadFileLists"></tbody>
//         </table>
//     </div>
//     <button type="button" className="layui-btn" id="fileListAction">开始上传</button>
// </div>
//
// <fieldset className="layui-elem-field layui-field-title" style="margin-top: 30px;">
//     <legend>绑定原始文件域</legend>
// </fieldset>
var demoListView = $('#uploadFileLists')
    ,uploadListIns = upload.render({
    elem: '#fileList'
    ,url: '/tFile/filesUpload' //改成您自己的上传接口
    ,accept: 'file'
    ,multiple: true
    ,auto: false
    , data: {uid: myuid}
    ,bindAction: '#fileListAction'
    ,choose: function(obj){
        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
        //读取本地文件
        obj.preview(function(index, file, result){
            var tr = $(['<tr id="upload-'+ index +'">'
                ,'<td>'+ file.name +'</td>'
                ,'<td>'+ (file.size/1024).toFixed(1) +'kb</td>'
                ,'<td>等待上传</td>'
                ,'<td>'
                ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                ,'</td>'
                ,'</tr>'].join(''));

            //单个重传
            tr.find('.demo-reload').on('click', function(){
                obj.upload(index, file);
            });

            //删除
            tr.find('.demo-delete').on('click', function(){
                delete files[index]; //删除对应的文件
                tr.remove();
                uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
            });
            demoListView.append(tr);
        });
        $("#fileListAction").click();
    }
    ,done: function(res, index, upload){
        console.log(res);
        if(res.code==200){ //上传成功
            var tr = demoListView.find('tr#upload-'+ index)
                ,tds = tr.children();
            tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
            tds.eq(3).html(''); //清空操作
            console.log('tr#upload-'+ index);
            $('tr#upload-'+ index).remove() ;
            return delete this.files[index]; //删除文件队列已经上传成功的文件

        }

        $("#uploadFileLists").html("");
        this.error(index, upload);

    }
    ,error: function(index, upload){
        var tr = demoListView.find('tr#upload-'+ index)
            ,tds = tr.children();
        tds.eq(2).html('<span style="color: #ff5722;">上传失败</span>');
        tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
    }
});
